<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>documentName</title>
</head>

<body>
  <div id="code"></div>

  <br>
  <br>
  <br>
  <br>
  <br>
  <br>

  <div id="code1"></div>

  <script src="./lib/jquery-3.5.1.min.js"></script>
  <script src="./lib/jquery.qrcode.min.js"></script>
  <script>
    $('#code').qrcode("http://www.baidu.com"); //任意字符串

    // 转换字符时
    // # 定义转化字符的方法
    function toUtf8(str) {
      var out, i, len, c;
      out = "";
      len = str.length;
      for (i = 0; i < len; i++) {
        c = str.charCodeAt(i);
        if ((c >= 0x0001) && (c <= 0x007F)) {
          out += str.charAt(i);
        } else if (c > 0x07FF) {
          out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
          out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
          out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
        } else {
          out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
          out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
        }
      }
      return out;
    }
    // # 使用
    var str = toUtf8("字符串测试！");
    $('#code1').qrcode(str)
  </script>
</body>

</html>